#if defined(_WIN32)
#pragma warning(disable: 4819)
#endif

#include <boost/optional.hpp>

#include <QtGui/QApplication>

#include "MRMPApplication.h"

#include "basic_typedef.h"
#include "EditDistanceCalculator.hpp"

#include "timer.hpp"

void test_time()
{
	Timer t(5000);
	Sleep(1000);
	if(t.is_time_up())
		return;
	printf("1");
	Sleep(1000);
	if(t.is_time_up())
		return;
	printf("2");
	Sleep(1000);
	if(t.is_time_up())
		return;
	printf("3");
	Sleep(1000);
	if(t.is_time_up())
		return;
	printf("4");
	Sleep(1000);
	if(t.is_time_up())
		return;
	printf("5");
	Sleep(1000);
	if(t.is_time_up())
		return;
	printf("6");
	printf("press any key to exit\n");
	getchar();
	return;
}

void test_edit_distance()
{
	std::vector<ConfSet> first_path;
	Conf a1(1,0);
	Conf a2(2,0);
	Conf a3(3,0);
	Conf a4(10,0);
	Conf a5(4,0);
	ConfSet a_c1;
	ConfSet a_c2;
	ConfSet a_c3;
	ConfSet a_c4;
	ConfSet a_c5;
	a_c1.push_back(a1);
	a_c2.push_back(a2);
	a_c3.push_back(a3);
	a_c4.push_back(a4);
	a_c5.push_back(a5);
	first_path.push_back(a_c1);
	first_path.push_back(a_c2);
	first_path.push_back(a_c3);
	first_path.push_back(a_c4);
	first_path.push_back(a_c5);

	std::vector<ConfSet> second_path;
	Conf b1(1,0);
	Conf b2(2,0);
	Conf b3(3,0);
	Conf b4(4,0);
	ConfSet b_c1;
	ConfSet b_c2;
	ConfSet b_c3;
	ConfSet b_c4;
	b_c1.push_back(b1);
	b_c2.push_back(b2);
	b_c3.push_back(b3);
	b_c4.push_back(b4);
	second_path.push_back(b_c1);
	second_path.push_back(b_c2);
	second_path.push_back(b_c3);
	second_path.push_back(b_c4);
	EditDistanceCalculator calc(first_path,second_path);

	std::vector<std::vector<UINT32>> connections_to_try=calc.get_connections_to_try();

	std::vector<std::vector<ConfSet>> points_to_connect;
	for(UINT32 i=0;i<connections_to_try.size();i++)
	{
		std::vector<ConfSet> pair_to_try;
		pair_to_try.push_back(first_path[connections_to_try[i][0]]);
		pair_to_try.push_back(second_path[connections_to_try[i][1]]);
		points_to_connect.push_back(pair_to_try);
	}

	for(UINT32 i=0;i<points_to_connect.size();i++)
	{
		Conf first_conf=(points_to_connect[i][0])[0];
		Conf second_conf=(points_to_connect[i][1])[0];
		printf("Connect: %f %f to %f %f\n",CGAL::to_double(first_conf.x()),CGAL::to_double(first_conf.y()),CGAL::to_double(second_conf.x()),CGAL::to_double(second_conf.y()));
	}
	printf("press any key to exit\n");
	getchar();

}

int main(int argc, char* argv[])
{
//	test_time();
//	test_edit_distance();
  QApplication a(argc, argv);
  MRMPApplication w;
  a.setActiveWindow(&w);
  w.show();
  a.setQuitOnLastWindowClosed(true);
  a.connect(qApp, SIGNAL(lastWindowClosed() ), qApp, SLOT( quit()));

  return a.exec();
	return 0;
}
